require("../util.js");
require("../component/components.js");
require("../component/basicSlide.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#newlyweds",
    data:{
        newUserVip:{},
        productList:{},
        productList1:[],
        productList2:[],
        list:{
            typeId:"",
            pageNumber:1
        },
        index:""
    },
    mounted:function(){
        this.getNewUserVip();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        //获取新人专享类型
        getNewUserVip:function(){
            var that=this;
            this.ajax({url:"/purchase/getNewUserVip",dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.newUserVip=b.json.data;
                    that.newUserVip&&that.newUserVip.types.forEach(function(val){
                        if(val.sortDate==0){
                            that.sortDate=val.sortDate;
                            that.list.typeId=val.typeId;
                            that.getNewUserVipList();
                        }
                    });
                    if(!that.list.typeId){
                        that.typeId=that.newUserVip.types[0].typeId;
                        that.sortDate=that.newUserVip.types[0].sortDate;
                    }
                }else{
                    vm.$refs.prompt.toast("获取轮播失败！")
                }
            });
        },
        //乐购子分类商品
        getNewUserVipList:function(){
            var that=this;
            console.log(that.list);
            this.ajax({url:"/purchase/getNewUserVipList",data:that.list,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.productList=b.json.data;
                    that.productList1=that.productList.list;
                    if(that.productList.pageNumber>1){
                        if(that.productList.list.length>0) {
                            that.productList2 = that.productList2.concat(b.json.data.list);
                        }
                    }else{
                        that.productList2= that.productList1;
                    }
                    console.log(that.productList2)
                    vm.loadFlag=false;
                }else{
                    that.productList={};
                    that.productList1=[];
                    that.productList2=[];
                    vm.$refs.prompt.toast("获取商品列表失败！")
                }
            });
        },
        getTab:function (item) {
            this.list.typeId=item.typeId;
            this.sortDate=item.sortDate;
            this.productList={};
            this.productList1=[];
            this.productList2=[];
            this.getNewUserVipList();
        },
        getData:function(data){
            if(data<10){
                return "0"+data+":00";
            }else{
                return data+":00";
            }
        },
        getNext:function(type,couponId){
            if(type==1){
                location.href="/purchase/couponInfo?type=1&couponId="+couponId;
            }
        }
    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
var loadFlag;
window.onscroll=function(){
    loadFlag = vm.productList.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()-50){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.list.pageNumber++;
            vm.getNewUserVipList();
            lazyload();
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};